﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Museum.DBAccess;

public partial class ChangePassword : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnReset_Click(object sender, EventArgs e)
    {

    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        int result = 0;
        int museumId = 0;
        try
        {
            //update pwd in DB
            if (Session["Username"] != null && Session["Role"] != null)
            {
                if (Session["MuseumId"] != null)
                {
                    museumId = Convert.ToInt32(Session["MuseumId"].ToString());
                }

                result = DBAccess.InsertOrUpdateUser(museumId, Convert.ToInt16(Session["Role"]), Session["Username"].ToString().Trim(), txtOldPassword.Text.Trim(), txtNewPassword.Text.Trim());

                if (result.Equals(-1))
                {
                    Alert.ShowMessage("Password changed successfully.");
                    Session.Clear();
                    Session.Abandon();
                    Response.Redirect("Login.aspx", false);
                }
                else
                    Alert.ShowMessage("Password not changed, please try again.");
            }
            else
                Alert.ShowMessage("Password cannot be changed for admin user.");
        }
        catch (Exception ex)
        {
            Alert.ShowMessage("Password not changed.");
            throw ex;
        }
    }
}